#!/usr/bin/env python

import sys,os,popen2
from time import strftime,localtime,time,sleep

list = ['http://172.31.25.227/phoneyc/4158.html',# fail: button's onclick event not implemented. 
'http://172.31.25.227/phoneyc/4226.html', 
'http://172.31.25.227/phoneyc/4230.html', 
'http://172.31.25.227/phoneyc/4237.html', 
'http://172.31.25.227/phoneyc/4250.html', 
'http://172.31.25.227/phoneyc/4351.html', 
'http://172.31.25.227/phoneyc/4420.html', 
'http://172.31.25.227/phoneyc/4427.html', 
'http://172.31.25.227/phoneyc/4594.html', 
'http://172.31.25.227/phoneyc/4613.html', 
'http://172.31.25.227/phoneyc/4663.html', 
'http://172.31.25.227/phoneyc/4829.html', 
'http://172.31.25.227/phoneyc/4869.html', 
'http://172.31.25.227/phoneyc/4874.html', 
'http://172.31.25.227/phoneyc/4875.html', 
'http://172.31.25.227/phoneyc/4894.html', 
'http://172.31.25.227/phoneyc/4903.html', 
'http://172.31.25.227/phoneyc/4909.html', 
'http://172.31.25.227/phoneyc/4918.html', 
'http://172.31.25.227/phoneyc/4932.html', 
'http://172.31.25.227/phoneyc/4967.html', 
'http://172.31.25.227/phoneyc/4974.html', 
'http://172.31.25.227/phoneyc/4979.html', 
'http://172.31.25.227/phoneyc/4982.html', 
'http://172.31.25.227/phoneyc/4986.html', 
'http://172.31.25.227/phoneyc/4987.html', 
'http://172.31.25.227/phoneyc/5025.html', 
'http://172.31.25.227/phoneyc/5043.html', 
'http://172.31.25.227/phoneyc/5045.html', 
'http://172.31.25.227/phoneyc/5049.html', 
'http://172.31.25.227/phoneyc/5051.html', 
'http://172.31.25.227/phoneyc/5052.html', 
'http://172.31.25.227/phoneyc/5153.html', 
'http://172.31.25.227/phoneyc/5188.html', 
'http://172.31.25.227/phoneyc/5190.html', 
'http://172.31.25.227/phoneyc/5193.html', 
'http://172.31.25.227/phoneyc/5205.html', 
'http://172.31.25.227/phoneyc/5217.html', 
'http://172.31.25.227/phoneyc/5225.html', 
'http://172.31.25.227/phoneyc/5264.html', 
'http://172.31.25.227/phoneyc/5271.html', 
'http://172.31.25.227/phoneyc/5272.html', 
'http://172.31.25.227/phoneyc/55875.html', 
'http://172.31.25.227/phoneyc/aol_ampx.html',  # no shellcode
'http://172.31.25.227/phoneyc/ARCserve_AddColumn_BoF.html',  #ok 
'http://172.31.25.227/phoneyc/CVE-2008-1309-Real.html', #na obfuscated
'http://172.31.25.227/phoneyc/domino.html',  # no
'http://172.31.25.227/phoneyc/gom.html',  # fail vb script Number.47
'http://172.31.25.227/phoneyc/hpinfo1.html',  # no
'http://172.31.25.227/phoneyc/hpinfo2.html', # no
'http://172.31.25.227/phoneyc/hpinfo3.html', #no
'http://172.31.25.227/phoneyc/hpinfo.html',  #no
'http://172.31.25.227/phoneyc/hpupdate1.html',  # no
'http://172.31.25.227/phoneyc/hpupdate2.html', # no
'http://172.31.25.227/phoneyc/intuit.html',  # fail Wrong shellcode
'http://172.31.25.227/phoneyc/msrichtxt.html', #no
'http://172.31.25.227/phoneyc/OurgameGLWorld.html', #fail Obfuscated
'http://172.31.25.227/phoneyc/Pps.html', #fail Obfuscated
'http://172.31.25.227/phoneyc/qvodctl-2.html',  # fail There is a valid download-exec shellcode but libemu test returns negative value.
'http://172.31.25.227/phoneyc/qvodctl.html', # no Number.59
'http://172.31.25.227/phoneyc/rgod_imesh.html',# fail Error Executing && libemu test failed to detect shellcode 
'http://172.31.25.227/phoneyc/show-283-1.html', #ok
'http://172.31.25.227/phoneyc/ssreader_0day.html', #ok
'http://172.31.25.227/phoneyc/storm_advancedOpen.htm', #no
'http://172.31.25.227/phoneyc/storm_backImage.htm', #no
'http://172.31.25.227/phoneyc/storm_isDVDPath.htm', #no
'http://172.31.25.227/phoneyc/storm_killbit.reg', #no
'http://172.31.25.227/phoneyc/storm_list_url.smpl', #no
'http://172.31.25.227/phoneyc/storm_nov10.html', #no DOM Error/no shellcode
'http://172.31.25.227/phoneyc/storm_rawParse.htm', #no
'http://172.31.25.227/phoneyc/storm_titleImage.htm',#no  Number 70 
'http://172.31.25.227/phoneyc/storm_URL.htm', #no
'http://172.31.25.227/phoneyc/test033.html', #no
'http://172.31.25.227/phoneyc/toshiba.html', #fail libemu test failed to detect shellcode
'http://172.31.25.227/phoneyc/xupload-2.html', #fail Wrong shellcode
'http://172.31.25.227/phoneyc/xupload.html'] #no

cmd = 'PYTHONPATH=lib/python python main.py '+list[int(sys.argv[1])]
logfile=open("batchresult/batch"+sys.argv[1]+".log","w")
logfile.write(cmd+"\n")
t0 = time()  
js_timeout = 200
P = popen2.Popen3(cmd, True)
while time() < t0 + js_timeout and P.poll() == -1:
     sleep(0.1)
sts = P.poll()
if sts == -1:  #timeout
     is_js_timeout = True
     os.kill(P.pid, signal.SIGTERM)
     print "sending SIGTERM to "+str(P.pid)
     try:
          outps,inps = popen2.popen2('ps aux | grep "%s"' % (cmd))
          psitem = outps.read()
          outps.close()
          inps.close()
          pidtokill=int(psitem.split()[1])
          os.kill(pidtokill, signal.SIGTERM)
          print "sending SIGTERM to "+str(pidtokill)
     except Exception:
          traceback.print_exc()
p = P.fromchild
e = P.childerr
w = P.tochild
out = p.read()
err = e.read()
t1 = time()
logfile.write(out+"\n")
logfile.write(err+"\n")
logfile.write("TOTAL TIME:"+str(t1-t0)+"\n")

